package com.headFirstModel.observerPattern.custom;

/**
 * 观察者:接收天气更新的信息并以特定的方式发布
 */
public class CurrentConditionsDisplay implements Observer,DisplayElement{
    private float temperature; //温度
    private float humidity;  //气压
    private Subject weatherData; //注册到的观察者

    public  CurrentConditionsDisplay(Subject weatherData){
        this.weatherData=weatherData;
        this.weatherData.registerObserver(this);
    }

    //把温度和湿度保存起来，调用display打印温度和湿度
    @Override
    public void update(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        display();
    }

    @Override
    public void display() {
        System.out.println("温度: " + temperature
                + "F, 湿度： " + humidity + "%");
    }
}
